<?php

/**
 * @author 
 * @copyright 2009
 */
$check = $db->query("SELECT template FROM {prefix}setting LIMIT 1");
$check = $check->fetch_array();
$check = $check['template'];
$templates = dirlist('../templates/');

if(!empty($_GET['file'])){	
	if(strtolower($_GET['file'] != $check)){
	$_GET['file'] = str_replace("/", " ", $_GET['file']);
	$_GET['file'] = str_replace("../", " ", $_GET['file']);
	$_GET['file'] = str_replace("..", " ", $_GET['file']);
	rmdirr('../templates/'.$_GET['file']);
	
	$log->write(8, 'com_install', 'NOW()', 'User has deleted template '.$_GET['file'], $_SESSION['id']);
	echo '<p class="msg done">'.Lang::getBackGlobal('install_delete_done').'</p>';
	echo '<meta http-equiv="refresh" content="4;url=index.php?p=install&type=del_tlp">';
	}else{
		echo '<p class="msg error">'.Lang::getBackGlobal('install_delete_used').'</p>';
	}
}

$i = 1;
echo '<table>';
echo "<tr><th>#</th><th>".Lang::getBackGlobal('install_template')."</th><th>".Lang::getBackGlobal('install_version')."</th><th>".Lang::getBackGlobal('install_author')."</th><th>".Lang::getBackGlobal('action')."</th></tr>";
foreach($templates as $key){
	
	if(is_file('..'.DIR_SEP.'templates'.DIR_SEP.$key.DIR_SEP.'info.xml')){

    $xml = simplexml_load_file('..'.DIR_SEP.'templates'.DIR_SEP.$key.DIR_SEP.'info.xml');
    $author = (string)$xml->info[0]->author;
    $version = (string)$xml->info[0]->version;

	}else{
		$author = 'unknown';
		$version = 'unknown';
	}
	
	if($key == $check){
		$action = "<em>".Lang::getBackGlobal('install_delete_used')."</em>";
	}else{
		$action = '<a href="#" onclick="javascript:confirm_uninstall(\''.$key.'\', \'index.php?p=install&type=del_tlp&file='.$key.'\');return false;">'.Lang::getBackGlobal('install_delete').'</a>';
	}
	
	echo '<tr><td>'.$i.'</td><td>'.$key.'</td><td>'.$version.'</td><td>'.$author.'</td><td>'.$action.'</td></tr>';
	$i++;
}
echo "\n</table>";
?>